
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
 * ClientLogin.java
 *
 * Created on Jan 25, 2011, 12:03:38 AM
 */

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;

final  class ClientLogin extends javax.swing.JFrame
{
    Systems systems=new Systems();
    Thread tread;Thread accountTitleThread;
    /** Creates new form Login */
    ClientLogin()
    {   
        this.setTitle("::. Milliscript MoneySpinner Suite Client 1.5.1");
        if(OpenMSApp.ApplicationLogon.equalsIgnoreCase("First"))
        {
            Splash ne=new Splash();
            ne.display();
            ne.setVisible(true);
            //loadSplashScreen();
            ne.dispose();
            System.out.println("Splash disposed.");
        }
        else
        {
            System.out.println("Splash Not Loaded.");
        }
        initComponents();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMSApp.class).getContext().getResourceMap(ClientLogin.class);
        String filePath=resourceMap.getResourcesDir()+"MiliscriptDMS_logo.png";
        java.net.URL url = resourceMap.getClassLoader().getResource(filePath);
        this.setIconImage(getToolkit().getImage (url));
        System.out.println(url);
//        java.awt.Image m=resourceMap.getImageIcon("MiliscriptDMS_logo.png").getImage();
//        this.setIconImage(resourceMap.getImageIcon("loginButton.icon").getImage());
        setLocationRelativeTo(this);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setDefaultLookAndFeelDecorated(true);
        this.getRootPane().setDefaultButton(loginButton);
        OpenMSApp.ApplicationLogon="More";
        Configuration.setConfigurations();
        String computerNetAddress="";
        serveripTextField.setText(Configuration.serverIPAddress);
        establishServerConnection();
        /**
         *
         * Code To Enforce Single Use of Software Per System
         *
        try
        {
            String try1=java.net.Inet4Address.getLocalHost().getHostAddress();
            computerNetAddress=java.net.InetAddress.getLocalHost().getHostName();
           
//            if(computerNetAddress.equals("Abiodun-PC")==false)
//            {
//                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," UNAUTHORIZED MACHINE ! \n ERROR CODE: 001001 ","LAUNCH ERROR",JOptionPane.ERROR_MESSAGE);
//                System.exit(0);
//            }
        }
        catch(Exception e)
        {

        }**/
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jIPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        serveripTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jCompanyComboBox = new javax.swing.JComboBox();
        usernameLabel = new javax.swing.JLabel();
        usernameTextField = new javax.swing.JTextField();
        passwordLabel = new javax.swing.JLabel();
        jPasswordField = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        loginButton = new javax.swing.JButton();
        jCheckBox1 = new javax.swing.JCheckBox();

        jPanel1.setName("jPanel1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMSApp.class).getContext().getResourceMap(ClientLogin.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        jIPanel.setBackground(resourceMap.getColor("jIPanel.background")); // NOI18N
        jIPanel.setName("jIPanel"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout jIPanelLayout = new javax.swing.GroupLayout(jIPanel);
        jIPanel.setLayout(jIPanelLayout);
        jIPanelLayout.setHorizontalGroup(
            jIPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jIPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jIPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addContainerGap(383, Short.MAX_VALUE))
        );
        jIPanelLayout.setVerticalGroup(
            jIPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jIPanelLayout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        serveripTextField.setFont(resourceMap.getFont("serveripTextField.font")); // NOI18N
        serveripTextField.setEnabled(false);
        serveripTextField.setName("serveripTextField"); // NOI18N
        serveripTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                serveripTextFieldActionPerformed(evt);
            }
        });
        serveripTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                serveripTextFieldKeyTyped(evt);
            }
        });

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jCompanyComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --" }));
        jCompanyComboBox.setName("jCompanyComboBox"); // NOI18N

        usernameLabel.setFont(resourceMap.getFont("usernameLabel.font")); // NOI18N
        usernameLabel.setText(resourceMap.getString("usernameLabel.text")); // NOI18N
        usernameLabel.setName("usernameLabel"); // NOI18N

        usernameTextField.setFont(resourceMap.getFont("usernameTextField.font")); // NOI18N
        usernameTextField.setText(resourceMap.getString("usernameTextField.text")); // NOI18N
        usernameTextField.setName("usernameTextField"); // NOI18N
        usernameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usernameTextFieldActionPerformed(evt);
            }
        });
        usernameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                usernameTextFieldKeyTyped(evt);
            }
        });

        passwordLabel.setFont(resourceMap.getFont("passwordLabel.font")); // NOI18N
        passwordLabel.setText(resourceMap.getString("passwordLabel.text")); // NOI18N
        passwordLabel.setName("passwordLabel"); // NOI18N

        jPasswordField.setFont(resourceMap.getFont("jPasswordField.font")); // NOI18N
        jPasswordField.setText(resourceMap.getString("jPasswordField.text")); // NOI18N
        jPasswordField.setName("jPasswordField"); // NOI18N
        jPasswordField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jPasswordFieldKeyTyped(evt);
            }
        });

        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        loginButton.setFont(resourceMap.getFont("loginButton.font")); // NOI18N
        loginButton.setIcon(resourceMap.getIcon("loginButton.icon")); // NOI18N
        loginButton.setText(resourceMap.getString("loginButton.text")); // NOI18N
        loginButton.setName("loginButton"); // NOI18N
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(usernameLabel)
                            .addComponent(loginButton, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1)
                            .addComponent(passwordLabel)
                            .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(serveripTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jCompanyComboBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(9, 9, 9)
                .addComponent(jCheckBox1)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addGap(4, 4, 4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox1)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(serveripTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCompanyComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(usernameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(13, 13, 13)
                                .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(passwordLabel)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(23, 23, 23)
                                        .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(13, 13, 13)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jIPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jIPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
          
    private void usernameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_usernameTextFieldActionPerformed

    private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
        // TODO add your handling code here:
        String companyAvailable=systems.getValue(OpenMSApp.Database_C, "Select * from company",1);
        
        if(String.valueOf(jCompanyComboBox.getSelectedItem()).trim().equalsIgnoreCase("-- Select --")&&companyAvailable.isEmpty()==false)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please select a company ","Execution ERROR",JOptionPane.ERROR_MESSAGE);
            return;
        }
        OpenMSApp.Database_A=String.valueOf(jCompanyComboBox.getSelectedItem()).trim().replace(" ", "_").replace("-", "0");
        String[] args={};
        String password=String.valueOf(jPasswordField.getPassword()).trim();
        String username=usernameTextField.getText().trim();
        String loginComputerAddress="";
        String computerNetAddress="";
        String adminAvailable=systems.getValue(OpenMSApp.Database_A, "Select * from login where cProcess = 'admin' and cStatus='Active'",1);
        try
        {

        computerNetAddress=java.net.InetAddress.getLocalHost().getHostName();
//        String try0=java.net.Inet4Address.getLocalHost().getCanonicalHostName();
//        String try1=java.net.Inet4Address.getLocalHost().getHostAddress();
//        String try2=java.net.Inet4Address.getLocalHost().getHostName();
//        String try3=java.net.Inet6Address.getLocalHost().getHostAddress();
//        String try4=java.net.Inet6Address.getLocalHost().getCanonicalHostName();
//        String try5=java.net.Inet6Address.getLocalHost().getHostName();
//        String try6=java.net.InetAddress.getLocalHost().getCanonicalHostName();
//        String try7=java.net.InetAddress.getLocalHost().getHostAddress();
        String try8=java.net.InetAddress.getLocalHost().getHostName();
        String try9=java.net.InetSocketAddress.createUnresolved("localhost", 0).getAddress().toString();
//        String try10;
        //System.out.println("This computer address= "+computerNetAddress);
        System.out.println("This computer inetSocket address= "+try9);
        }catch(Exception e)
        { System.out.println("Error occured while retrieving localHostAddress"+e);}
        String computerUserName=System.getProperty("user.name");
        String osName=System.getProperty("os.name");
        System.out.println(computerUserName+" "+osName);
        loginComputerAddress=computerUserName+"@"+computerNetAddress;
        System.out.println("LoginIP: "+Configuration.serverIPAddress);
        Connect.alertRollBack="N";
        if(usernameTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Your Username ","Execution ERROR",JOptionPane.ERROR_MESSAGE);
            return;
        }
         if(String.valueOf(jPasswordField.getPassword()).trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Your Password ","Execution ERROR",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(usernameTextField.getText().trim().equals("mS")&&password.equals("DMS")&&adminAvailable.isEmpty()==true)
        {
            //setUserParameter(usernameTextField.getText());
            OpenMSApp.EmployeeName="System Setup";
            OpenMSApp.launch(OpenMSApp.class, args);
            this.dispose();
            return;
        }
        else
        {
            String access=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnConfirmLogin"+Connect.procInitStart+"'"+username+"' , '"+password+"', '"+loginComputerAddress+"'"+Connect.procInitEnd, "cState");

            String trialState=systems.getValue(OpenMSApp.Database_C, Connect.procInit+" prnConfirmTrial"+Connect.procInitStart+"'"+OpenMSApp.trialClientCode+"' , '"+loginComputerAddress+"'"+Connect.procInitEnd, "cState");

            if(trialState.equalsIgnoreCase("expired"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"SORRY, THE TRIAL PERIOD OF THIS SOFTWARE HAS EXPIRED !","Execution ERROR",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(trialState.equalsIgnoreCase("valid"))
            {
                String trialDay=systems.getValue(OpenMSApp.Database_C, Connect.procInit+" prnConfirmTrial"+Connect.procInitStart+"'"+OpenMSApp.trialClientCode+"' , '"+loginComputerAddress+"'"+Connect.procInitEnd, "iDayLeft");
                OpenMSApp.trialDay=trialDay;
                if(Integer.parseInt(trialDay)<7)
                {
                    JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," THE TRIAL PERIOD OF MILLISCRIPT MONEYSPINNER 1.4.0 \n IS NOW "+trialDay+" DAYS LEFT","ERROR !",JOptionPane.ERROR_MESSAGE);
                }
            }
            if(access.equalsIgnoreCase("Blocked"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"             Access Blocked !\n Please see your System Administrator","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(access.equalsIgnoreCase("Active"))
            {
                setUserParameter(usernameTextField.getText());
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"      Welcome ! \n "+OpenMSApp.EmployeeName,"Execution COMPLETE",JOptionPane.INFORMATION_MESSAGE);

                OpenMSApp.launch(OpenMSApp.class, args);
                this.dispose();
            }
            else
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Invalid Username and Password Combination","Execution ERROR",JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
    }//GEN-LAST:event_loginButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        Connect.closeMainConnection();
        System.exit(0);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void usernameTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_usernameTextFieldKeyTyped
        // TODO add your handling code here:
        String value=usernameTextField.getText();
        if(value.length()>9)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (10) Exceeded ","Execution ERROR",JOptionPane.ERROR_MESSAGE);
            String newValue=String.copyValueOf(value.toCharArray(),0, 9);
            usernameTextField.setText(newValue);
        }

    }//GEN-LAST:event_usernameTextFieldKeyTyped

    private void jPasswordFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordFieldKeyTyped
        // TODO add your handling code here:
        String value=String.valueOf(jPasswordField.getPassword());
        if(value.length()>9)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (10) Exceeded ","Execution ERROR",JOptionPane.ERROR_MESSAGE);
            String newValue="";
            jPasswordField.setText(newValue);
        }
    }//GEN-LAST:event_jPasswordFieldKeyTyped

private void serveripTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serveripTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_serveripTextFieldActionPerformed

private void serveripTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_serveripTextFieldKeyTyped
    if(evt.getKeyChar()=='\n'){System.out.println("key char= "+evt.getKeyChar());establishServerConnection();}
}//GEN-LAST:event_serveripTextFieldKeyTyped

private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
    if(jCheckBox1.isSelected())
        serveripTextField.setEnabled(true);
    else{
        serveripTextField.setEnabled(false);
        serveripTextField.setText(Configuration.initServerIPAddress);
        establishServerConnection();
    }
}//GEN-LAST:event_jCheckBox1ActionPerformed
    void setUserParameter(String userName)
    {
        Systems systems=new Systems();
        OpenMSApp.LoginCode=systems.getValue(OpenMSApp.Database_A, "Select * from login where vusername= '"+userName+"'", "cLoginCode").trim();
        OpenMSApp.EmployeeID=systems.getValue(OpenMSApp.Database_A, "Select * from login where vusername= '"+userName+"'", "cEmployeeID").trim();
        OpenMSApp.EmployeeName=systems.getValue(OpenMSApp.Database_A,"Select * from Employee where cEmployeeID= '"+OpenMSApp.EmployeeID+"'","vFirstName").trim()+" "+
                        systems.getValue(OpenMSApp.Database_A,"Select * from Employee where cEmployeeID= '"+OpenMSApp.EmployeeID+"'","vMiddleName").trim()+" "+
                        systems.getValue(OpenMSApp.Database_A,"Select * from Employee where cEmployeeID= '"+OpenMSApp.EmployeeID+"'","vlastName").trim();
        OpenMSApp.CompanyName=jCompanyComboBox.getSelectedItem().toString();
        OpenMSApp.UserName=userName;
        OpenMSApp.userProcess=systems.getValue(OpenMSApp.Database_A, "Select * from login where vusername= '"+userName+"'", "cProcess").trim();
    }
    void establishServerConnection()
    {
        String serverIP=serveripTextField.getText();
        Configuration.serverIPAddress="null";
        try
        {   
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            java.sql.Connection connect=java.sql.DriverManager.getConnection("jdbc:mysql://"+serverIP+":1202","root","milli");
            connect.prepareStatement("Select * from company");
            Configuration.serverIPAddress=serverIP;
            OpenMSApp.curIP=" | Connection IP: "+serverIP;
            Connect.createMSSQLConnection();
            resetCompany();
            jLabel3.setText("Connected to server @ "+serverIP);
            System.out.println("serverip= "+Configuration.serverIPAddress);
            connect.close();
        }
        catch(Exception e)
        {
            jLabel3.setText("Unable to establish connection @ "+serverIP);
            String[] company={"-- Select --"};
            jCompanyComboBox.setModel(new DefaultComboBoxModel(company));
            System.out.println("serverip d= "+Configuration.serverIPAddress);
            java.io.File f=new java.io.File("conError.txt");
            e.printStackTrace();
            try{
            java.io.FileWriter fw=new java.io.FileWriter(f,true);
            fw.write(e.toString());
            fw.flush();fw.close();
            }catch(Exception ex){ex.printStackTrace();}
        }
    }
    void resetCompany()
    {
        String[] company=systems.getTableDataArray(OpenMSApp.Database_C,"Company",2);
        company[0]="-- Select --";

        jCompanyComboBox.setModel(new DefaultComboBoxModel(company));
    }
    
   void loadSplashScreen()
  {
      tread=new Thread();
     System.out.println("Splash Loaded");
    //Start the thread
      try
      {
        //Display the FormSplash for 10 seconds
        System.out.println("Splash sleeping...");
        tread.sleep(5000);
      }
      catch(InterruptedException e)
      {
      }

  }

    /**
    * @param args the command line arguments
    */


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jCompanyComboBox;
    private javax.swing.JPanel jIPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPasswordField jPasswordField;
    private javax.swing.JButton loginButton;
    private javax.swing.JLabel passwordLabel;
    private javax.swing.JTextField serveripTextField;
    private javax.swing.JLabel usernameLabel;
    private javax.swing.JTextField usernameTextField;
    // End of variables declaration//GEN-END:variables

}
